<template>
	<div class="send-message">
		<button @click="sendMessage">打开网页</button>
	</div>
</template>

<script>
export default {
	data() {
		return {
			domain: 'https://127.0.0.1:8081',
			message: 'Hello!  The time is: ' + new Date().getTime()
		};
	},
	mounted() {
		//监听消息反馈
		window.addEventListener(
			'message',
			function(event) {
				if (event.origin !== 'https://127.0.0.1:8081') return;
				console.log('received response:  ', event.data);
			},
			false
		);
	},
	methods: {
		sendMessage() {
			let myPage = window.open(this.domain + '/#/message', 'myWindow');
			myPage.postMessage(this.message, this.domain);
		}
	}
};
</script>

<style></style>
